using System.Text;
using MathMLToCSharp.Builders;

namespace MathMLToCSharp.Entities
{
  /// <summary>
  /// Number.
  /// </summary>
  internal class Mn : WithTextContent
  {
    public Mn(string content) : base(content) {}

    /// <summary>
    /// Returns <c>true</c> if the content is an integer greater than 1 (i.e., 2, 3, etc.)
    /// </summary>
    public bool IsIntegerGreaterThan1
    {
      get
      {
        try
        {
          double d = double.Parse(content);
          if (System.Math.Floor(d) == d)
            if (d > 1.0)
              return true;
          return false;
        } 
        catch
        {
          return false;
        }
      }
    }

    public int IntegerValue
    {
      get
      {
        return int.Parse(content);
      }
    }

    public override void Visit(CodeBuilder cb, BuildContext bc)
    {
      base.Visit(cb, bc);
      if (bc.Options.NumberPostfix && !bc.Options.SubscriptMode)
        cb.Append(Semantics.postfixForDataType(bc.Options.EqnDataType));
    }
  }
}